<!-- 抽取专家，转派三方 弹窗-->
<template>
  <div class="turn-three-audit-dialog">
    <el-dialog
      :title="title"
      :visible.sync="turnThreeAuditDialogShow"
      width="628px"
      :before-close="handleClose"
      :close-on-click-modal="false"
      custom-class="dialog-box"
    >
      <el-form
        :model="queryParams"
        :rules="rules"
        ref="queryParams"
        label-width="120px"
      >
        <el-form-item label="请选择">
          <el-select
            v-model="selectWay"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="dict in selectWayOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="handleExtractExpert"
            v-if="selectWay === 0"
            >去抽取</el-button
          >
        </el-form-item>
        <el-form-item
          label="评审任务名称"
          prop="taskName"
          v-if="selectWay === 1"
        >
          <el-input v-model="queryParams.taskName" maxlength="32"></el-input>
        </el-form-item>
        <el-form-item
          label="选择第三方机构"
          prop="ormId"
          v-if="selectWay === 1"
        >
          <el-select
            v-model="queryParams.ormId"
            placeholder="请选择机构"
            style="width: 100%"
          >
            <el-option
              v-for="item in manangmentList"
              :key="item.ormId"
              :label="item.organizationName"
              :value="item.ormId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" v-if="selectWay === 1">
          <el-input
            type="textarea"
            v-model="queryParams.approvalOpinion"
            maxlength="200"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="审核意见" prop="approvalOpinion" v-if="selectWay === 2">
          <el-input
            type="textarea"
            v-model="queryParams.approvalOpinion"
            maxlength="200"
            show-word-limit
          ></el-input>
        </el-form-item>
        <div class="select-template" v-if="selectWay === 2">
          <el-dropdown trigger="click" @command="handleCommand" placement="top">
            <span class="el-dropdown-link">
              选择模版<i class="icon-arrow-down el-icon-folder-remove"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                icon="el-icon-circle-check"
                v-for="dict in selectDemoList"
                :key="dict.dictValue"
                :command="dict.dictValue"
                >{{ dict.dictLabel }}</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer" v-if="selectWay === 1 || selectWay === 2">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getManagement, getTurnToThress, getReturnRepeated } from "@/api/manage/manage";
export default {
  name: "turntosendDialog",
  props: {
    turnThreeAuditDialogShow: {
      type: Boolean,
      default: "",
    },
    type: {
      type: String,
      default: "",
    },
    proid: {
      type: String,
      default: "",
    },
    auditData: {
      type: Object,
      default: () => {},
    },
    //项目属性 0 方案评审 1 年度计划
    reviewType: {
      type: String,
      default: "",
    },
  },
  inject: ["reload"],
  data() {
    return {
      title:'抽取专家',
      rules: {
        taskName: [{ required: true, message: "请输入", trigger: "blur" }],
        ormId: [{ required: true, message: "请选择", trigger: "change" }],
      },
      queryParams: {
        taskName: "",
        ormId: "",
        approvalOpinion: "",
      },
      manangmentList: [],
      selectWay: 0,
      // 选择方式数据字典
      selectWayOptions: [
        { dictValue: 0, dictLabel: "抽取专家" },
        { dictValue: 1, dictLabel: "转派三方" },
        { dictValue: 2, dictLabel: "退回重申" },
      ],
      // 选择模板数据字典
      selectDemoList: [
        { dictValue: "方案描述不充分1", dictLabel: "方案描述不充分1" },
        { dictValue: "方案描述不充分2", dictLabel: "方案描述不充分2" },
        { dictValue: "方案描述不充分3", dictLabel: "方案描述不充分3" },
      ],
    };
  },
  mounted() {},
  watch: {
    selectWay(val) {
      this.$refs.queryParams.resetFields();
      this.getManagementList();
      if (val === 1) {
        this.queryParams.taskName =
          this.auditData.name + this.auditData.stag + "评审";
        this.title='转派三方'
      }else{
        this.title='抽取专家'
      }
    },
  },
  created() {},
  methods: {
    /** 取消按钮 */
    handleClose() {
      this.selectWay = 0;
      this.$refs.queryParams.resetFields();
      this.$emit("changeShowDialog", "false"); //调用父组件的自定义事件，并传值
    },
    /** 抽取专家操作 */
    handleExtractExpert() {
      if (this.auditData.proId) {
        this.$router.push({
          path: "/business_manage/manage/projectPlan",
          query: {
            info:
              this.auditData.name +
              this.auditData.stag +
              "评审." +
              this.reviewType,
            projectId: this.auditData.proId,
            enterType: "manage",
          },
        });
      }
    },
    /** 确定按钮 */
    submitForm() {
      this.$refs.queryParams.validate((valid) => {
        if (valid) {
          this.queryParams.proid = this.proid;
          if(this.selectWay === 1){
            getTurnToThress(this.queryParams).then((res) => {
              if (res.code == 200) {
                this.$message.success("操作成功");
                this.$refs.queryParams.resetFields();
                this.$emit("changeShowDialog", "false");
                this.reload();
              }
            });
          }else if(this.selectWay === 2){
            let data ={
              proId:this.proid,
              approvalOpinion:this.queryParams.approvalOpinion
            }
            getReturnRepeated(data).then((res) => {
              if (res.code == 200) {
                this.$message.success("操作成功");
                this.$refs.queryParams.resetFields();
                this.$emit("changeShowDialog", "false");
                this.reload();
              }
            });
          }
          
        } else {
          return false;
        }
      });
    },
    getManagementList() {
      getManagement().then((res) => {
        this.manangmentList = res;
      });
    },
    // 选择模板内容
    handleCommand(command) {
      this.queryParams.approvalOpinion = command;
    },
  },
};
</script>

<style lang="scss">
.turn-three-audit-dialog .dialog-box .el-form-item .el-input__inner {
  width: 100%;
}
.turn-three-audit-dialog .dialog-box .el-form-item .el-textarea__inner {
  width: 100%;
}
.turn-three-audit-dialog{
  // 下载模板样式修改
  .select-template {
    .el-dropdown-link {
      color: #3171ee;
    }
    .icon-arrow-down {
      margin-left: 10px;
      color: #3171ee;
    }
    // width: 100%;
    display: flex;
    align-items: center;
    justify-content: right;
    font-size: 14px;
    font-family: PingFang SC, PingFang SC-Regular;
    font-weight: 400;
    text-align: LEFT;
    color: #3171ee;
    margin-left: 30%;
    margin-bottom: 20px;
    cursor: pointer;
    img {
      margin-left: 10px;
    }
  }
}
</style>
